/**
* @author AlbertDarren
* @contact 2563491540@qq.com
*/
#include <cstdio>

using namespace std;

int main_1031_2()
{
    int weights[]={7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2};
    char ZM[]="10X98765432",ID[19]={0};
    bool isAllPassed=true;
    int N;
    scanf("%d",&N);
    for (int i=0;i<N ; ++i)
    {
        scanf("%s",ID);
        int sum=0,j;
        for (j=0;j<17 ;++j )
        {
            if (ID[j]<'0'||ID[j]>'9')
            {
                isAllPassed=false;
                break;
            }
        }
        if (j<17)
        {
            printf("%s\n",ID);
        }
        else
        {
            for (int k=0;k<17;++k )
            {
                sum+=(ID[k]-'0')*weights[k];
            }
            if (ZM[sum%11]!=ID[17])
            {
                isAllPassed=false;
                printf("%s\n",ID);
            }
        }
    }
    if (isAllPassed)
    {
        printf("All passed");
    }
	return 0;
}
